<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<link rel="stylesheet" type="text/css" href="/skin/css/amazeui.min1.css" />
	<link href="/skin/font/iconfont.css" rel="stylesheet" type="text/css" />
	<link href="/skin/css/index.css" rel="stylesheet" type="text/css" />
<script src="/user/js/jquery.js"></script>
<meta name="Keywords" content="" />
<meta name="Description" content="" />
<title>地址列表-会员中心</title>
<style>

.addr-list{ padding:0.2rem .16rem; }
.addr-item{ position:relative; overflow:hidden; margin-bottom:0.2rem; border-radius:0.06rem; }

/* 关键：内容宽度 = 可视宽度 + 删除按钮宽度(0.44rem) */
.addr-swipe{
	display:flex;
	width: calc(100% + 0.44rem);
	transform: translateX(0);
	transition: transform .2s ease;
}

.addr-actions{ flex:0 0 0.44rem; display:flex; }
.addr-actions .del-btn{
	flex:1; background:#ef4444; color:#fff; border:0; font-size:0.12rem;
}

.addr-cell{
	flex:1; background:#fff; padding:0.2rem;
	box-shadow:0 0.03rem 0.18rem rgba(0,0,0,.05);
	display: flex;
	align-items: flex-start;
	gap: 0.12rem;
}
.addr-content{
	flex: 1;
	min-width: 0;
}
.addr-hd{ display:flex; align-items:center; flex-wrap: wrap; margin-bottom:0.04rem; }
.addr-name{ font-size:0.18rem; font-weight:600; color:#111827; }
.addr-phone{ font-size:0.18rem; font-weight:600; color:#111827; margin-left:0.04rem; }
.addr-badge{
	vertical-align: super;
	margin-left: .1rem;
	font-size:0.12rem; padding:0.02rem 0.065rem; background:#0f5132; color:#d1fae5; border-radius:0.03rem;
}
.addr-edit-icon{
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	height: 100%;
	margin-top: 0.02rem;
}
.addr-edit-icon img{
	width: 0.24rem;
	height: 0.24rem;
	object-fit: contain;
	display: block;
}
.addr-txt{ font-size:0.13rem; color:#4b5563; line-height:1.6; }
.addr-op{ margin-top:0.05rem; display:flex; gap:0.07rem; align-items:center; color:#64748b; }
.addr-op .set-default{ font-size: .12rem }

/* 底部新增按钮条 */
.addr-addbar{
	position:sticky; bottom:0;
	background:linear-gradient(to top,#f3f5f8 60%,rgba(243,245,248,0));
	padding:0 .475rem;
}

/* 列表底部留出空间，避免被按钮遮挡：0.25rem 按钮 + 0.12rem 间距 */
.addr-list{ padding-bottom: 0.37rem; }

/* 固定底部新增按钮（含 iOS 安全区） */
.addr-addfixed{
	position: fixed;
	left: 0; right: 0;
	bottom: 0;
	padding: 0.475rem 0.475rem calc(0.25rem + env(safe-area-inset-bottom,0));
	background: rgba(243,245,248,.96);
	backdrop-filter: blur(4px);
	z-index: 999;
}
.addr-addbtn{
	display:block;
	width:100%;
	height:0.48rem;
	line-height:0.48rem;
	text-align:center;
	background:#253043;
	color:#fff;
	border-radius:0.02rem;
	font-size:0.16rem;
	font-weight:700;
}
</style>
</head>
<body class="cart">
<header id="header">
	<section class="head-b head-b1">
		<span class="u-left"><a href="javascript:history.go(-1);" class="back"><img src="/skin/img/back.png"></a></span>
		<h1 id="t0">地址列表</h1>
		<div class="u-right" href="#">
			<a href="/" class="hSearch right"><img src="/skin/img/i_home.png"></a>
		</div>
	</section>
</header>

{if($msg==1)}
<div class="addr-list">
	{loop $dlist $key as $list}
		<div class="addr-item" data-id="{$list[Id]}">
			<div class="addr-swipe">
				<div class="addr-cell add_edit" data="{$list[Id]}">
					<div class="addr-content" id="clickAddress" data-id="{$list[Id]}">
						<div class="addr-hd">
							<span class="addr-name">{$list[tname]}</span>
							<span class="addr-phone">{$list[phone]}</span>
							{if($list['type']!=0)}<span class="addr-badge">默认</span>{/if}
						</div>
						<div class="addr-txt">{$list[address]}</div>
						<div class="addr-op">
							{if($list['type']==0)}
							<span class="set-default" style="color:#16a34a;" data-id="{$list[Id]}">设为默认</span>
							{/if}
							<!-- <a class="choose" href="/cart.php?id={$list[Id]}">选择地址</a> -->
						</div>
					</div>
					<a href="address_edit.php?id={$list[Id]}" class="addr-edit-icon" onclick="event.stopPropagation();">
						<img src="/skin/img/icon_edit.png" alt="编辑" />
					</a>
				</div>
				<div class="addr-actions">
					<button type="button" class="del-btn" data-id="{$list[Id]}">删除</button>
				</div>
			</div>
		</div>
	{/loop}
	</div>
	
	<div class="addr-addfixed">
		<a href="address_add.php?t={$t}" class="addr-addbtn">＋ 新增地址</a>
	</div>
{else}
<div class="none"><span>您还未添加收货地址</span><a style='font-size:14px; color:#1a2445; font-weight:bold;' href="address_add.php?t={$t}">立即添加</a></div>
{/if}
<script>
// 删除
$(document).on("click",".del-btn",function(e){
	e.stopPropagation();
	var id = $(this).attr("data-id");
	if(!confirm("确认删除？")) return;
	$.ajax({
		type:"post", dataType:"json",
		url:"/Moudelu.php?m=m&a=add_del", data:"id="+id,
		success:function(d){
			if(d[0]==2){ window.location.href='login.php'; return; }
			if(d[0]==0){ alert(d[1]); }
			else{ window.location.href='/user/address.php'; }
		}
	});
});

// 设为默认
$(document).on("click",".set-default",function(e){
	e.stopPropagation();
	var id = $(this).attr("data-id");
	$.ajax({
		type:"post", dataType:"json",
		url:"/Moudelu.php?m=m&a=add_default", data:"id="+id,
		success:function(d){
			if(d[0]==2){ window.location.href='login.php'; return; }
			if(d[0]==0){ alert(d[1]); }
			else{
				{if($t==1)} window.location.href='/cart.php';
				{else} window.location.href='/user/address.php'; {/if}
			}
		}
	});
});

// 点击卡片进入编辑
$(document).on("click","#clickAddress",function(){
	var id = $(this).attr("data-id");
	window.location.href='/cart.php?id='+id;
});

// 阻止操作区域冒泡
$(document).on("click",".addr-op",function(e){ e.stopPropagation(); });
// 设计稿 375px，1rem = 100px，换算方法：px值 ÷ 100 = rem值
(function(){
	var docEl = document.documentElement;
	var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
	function recalc() {
		var clientWidth = docEl.clientWidth;
		if (!clientWidth) return;
		docEl.style.fontSize = (clientWidth / 375 * 100) + 'px';
	}
	if (!document.addEventListener) return;
	window.addEventListener(resizeEvt, recalc, false);
	document.addEventListener('DOMContentLoaded', recalc, false);
	recalc();
})();

// 左滑显示删除
(function(){
	var openEl = null, startX=0, curX=0;
	var maxShift = parseFloat(getComputedStyle(document.documentElement).fontSize) * 0.44; // 0.44rem -> px

	function closeOpen(){ if(openEl){ openEl.style.transform='translateX(0)'; openEl=null; } }

	document.querySelectorAll('.addr-swipe').forEach(function(row){
		row.addEventListener('touchstart', function(e){
			startX = e.touches[0].clientX; curX = 0;
			if(openEl && openEl!==row) closeOpen();
		}, {passive:true});
		row.addEventListener('touchmove', function(e){
			curX = e.touches[0].clientX - startX;
			if(curX < 0){
				var dx = Math.max(-maxShift, curX);
				row.style.transform = 'translateX('+dx+'px)';
				e.preventDefault();
			}
		}, {passive:false});
		row.addEventListener('touchend', function(){
			if(curX < -maxShift/2){ row.style.transform='translateX('+(-maxShift)+'px)'; openEl=row; }
			else { row.style.transform='translateX(0)'; if(openEl===row) openEl=null; }
		});
	});
	document.addEventListener('click',function(){ closeOpen(); });
})();
</script>
<!-- <?php include("foot.php");?> -->
</body>
</html>